<html>
<head><meta charset="utf-8"><title>implementing &quot;abort on FFI call&quot; · project-ffi-unwind · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/index.html">project-ffi-unwind</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html">implementing &quot;abort on FFI call&quot;</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="180636576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180636576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180636576">(Nov 13 2019 at 15:21)</a>:</h4>
<p>So I was thinking about how to measure the impact of a proposal where the C ABI permits unwinding but -- if we are <code>-Cpanic=abort</code> -- we abort if unwinding actually occurs (versus UB).</p>
<p>I think the way to do this would be to modify the <code>no_landing_pads</code> transformation. Right now, it just removes all landing pads. I think what we would actually want is to check if this is a function call and -- in the case where it is -- inspect the ABI and callee. If the ABI is not Rust (or Rust call), and the callee is not known, then we would instead rewrite the unwind to branch to a block with <code>TerminatorKind::Abort</code>.</p>
<p>We might or might not have such a block today, so we can (lazilly, and at most once) create such a block.</p>



<a name="180636595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180636595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180636595">(Nov 13 2019 at 15:21)</a>:</h4>
<p>There might be some other assertions that need to be adjusted.</p>



<a name="180638968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180638968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180638968">(Nov 13 2019 at 15:43)</a>:</h4>
<p>I put in some work towards implementing this in the <a href="https://github.com/nikomatsakis/rust/tree/abort-on-ffi-call" target="_blank" title="https://github.com/nikomatsakis/rust/tree/abort-on-ffi-call">abort-on-ffi-call</a> branch -- not building yet or <em>quite</em> complete, but almost there (I think..?)</p>



<a name="180643343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180643343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180643343">(Nov 13 2019 at 16:19)</a>:</h4>
<p>OK I think this is building now, but I really have to stop and do other stuff</p>



<a name="180646173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180646173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180646173">(Nov 13 2019 at 16:45)</a>:</h4>
<p>(OK, it builds, but it doesn't work; I don't quite know what's going on, something to do with the <code>remove_noop_landing_pads</code> pass...)</p>



<a name="180646215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180646215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180646215">(Nov 13 2019 at 16:46)</a>:</h4>
<p><em>oh</em>, it's cause the landing pad has nothing to do I guess</p>



<a name="180692430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180692430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180692430">(Nov 14 2019 at 01:47)</a>:</h4>
<p>ok, I think that is working now -- the MIR looks right, but it's sort of hard to test. I tried hacking up some C++ function that throws even though it's not supposed to, but C++ keeps calling <code>std::terminate</code> since it can't find a catch handler (true even when I put the Rust function sandwiched between two C++ functions, and one of them has a <code>catch</code>)</p>



<a name="180697354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180697354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180697354">(Nov 14 2019 at 03:39)</a>:</h4>
<p>Wow, the Rust sandwich breaks <code>catch</code>? I did not expect that at all.</p>



<a name="180718056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180718056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180718056">(Nov 14 2019 at 10:34)</a>:</h4>
<p>I can only presume it has to do with interrupting the ability to walk up the stack and find the catch handler somehow? This is true on linux, at least.</p>



<a name="180718066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180718066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180718066">(Nov 14 2019 at 10:35)</a>:</h4>
<p>Well hey, it does abort... :)</p>



<a name="180731689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180731689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180731689">(Nov 14 2019 at 13:48)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> What does the LLVM IR look like?</p>



<a name="180731779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180731779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180731779">(Nov 14 2019 at 13:49)</a>:</h4>
<blockquote>
<p>nikomatsakis 2:47 AM   <br>
ok, I think that is working now -- the MIR looks right, but it's sort of hard to test. I tried hacking up some C++ function that throws even though it's not supposed to, but C++ keeps calling std::terminate since it can't find a catch handler (true even when I put the Rust function sandwiched between two C++ functions, and one of them has a catch)</p>
</blockquote>
<p><code>noexcept</code> C++ functions have an "abort-on-panic" shim that calls <code>std::terminate</code></p>



<a name="180731953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180731953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180731953">(Nov 14 2019 at 13:50)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> one needs to create a normal C++ function that throws, and then just use <code>extern "C" { ... }</code></p>



<a name="180731956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180731956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180731956">(Nov 14 2019 at 13:51)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> I did not declare anything <code>noexcept</code></p>



<a name="180731984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180731984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180731984">(Nov 14 2019 at 13:51)</a>:</h4>
<p>I did create a normal C++ function</p>



<a name="180731994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180731994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180731994">(Nov 14 2019 at 13:51)</a>:</h4>
<p>I'll push the project</p>



<a name="180732014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180732014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180732014">(Nov 14 2019 at 13:51)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> I'm not sure :) I have to look how to save the LLVM IR, I forget</p>



<a name="180732018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180732018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180732018">(Nov 14 2019 at 13:51)</a>:</h4>
<p>I'll take a look</p>



<a name="180732575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180732575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180732575">(Nov 14 2019 at 13:56)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> I pushed my example <a href="https://github.com/nikomatsakis/rust-ffi-examples/tree/abort-on-ffi-call" target="_blank" title="https://github.com/nikomatsakis/rust-ffi-examples/tree/abort-on-ffi-call">to this branch</a> -- it was the rust-to-cpp and cpp-to-rust (sandwich)</p>



<a name="180732587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180732587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180732587">(Nov 14 2019 at 13:57)</a>:</h4>
<p>in both cases, I get the same error</p>



<a name="180732619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180732619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180732619">(Nov 14 2019 at 13:57)</a>:</h4>
<p>looking at the c++ referenece manual, it suggested that if there is no <code>catch</code> block then C++ will terminate (which fits what I'm seeing)</p>



<a name="180732647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180732647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180732647">(Nov 14 2019 at 13:57)</a>:</h4>
<p>it works without Rust in between</p>



<a name="180732658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180732658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180732658">(Nov 14 2019 at 13:57)</a>:</h4>
<p>(that is, the throw gets caught)</p>



<a name="180732796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180732796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180732796">(Nov 14 2019 at 13:59)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> I think the llvm output is in <a href="https://gist.github.com/nikomatsakis/d48b3cea0c46c44e8adc519585c23f95" target="_blank" title="https://gist.github.com/nikomatsakis/d48b3cea0c46c44e8adc519585c23f95">this gist</a></p>



<a name="180732828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180732828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180732828">(Nov 14 2019 at 13:59)</a>:</h4>
<p>I guess it has <code>nounwind</code> and other stuff</p>



<a name="180732830"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180732830" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180732830">(Nov 14 2019 at 13:59)</a>:</h4>
<p>oh wait</p>



<a name="180732835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180732835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180732835">(Nov 14 2019 at 13:59)</a>:</h4>
<p>that wasn't built w/ my branch</p>



<a name="180732939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180732939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180732939">(Nov 14 2019 at 14:00)</a>:</h4>
<p><a href="https://gist.github.com/nikomatsakis/44fb90f7bb97e14735855f7fd3dc3192" target="_blank" title="https://gist.github.com/nikomatsakis/44fb90f7bb97e14735855f7fd3dc3192">llvm output from my branch</a></p>



<a name="180733095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180733095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180733095">(Nov 14 2019 at 14:02)</a>:</h4>
<p>(this is a debug build)</p>



<a name="180733327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180733327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180733327">(Nov 14 2019 at 14:04)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> Your function needs the <code>uwtable</code> attribute, otherwise dwarf tables aren't generated and the unwinder doesn't know how to unwind past your function to find the actual catch block in the caller.</p>



<a name="180733393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180733393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180733393">(Nov 14 2019 at 14:05)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> ok -- would it make sense to have that only for the "leaf functions" that actually invoke FFI?</p>



<a name="180733416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180733416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180733416">(Nov 14 2019 at 14:05)</a>:</h4>
<p>(after all, I'm going to catch any unwinding and trap)</p>



<a name="180733475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180733475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180733475">(Nov 14 2019 at 14:06)</a>:</h4>
<p>Also in optimized builds the landing pad is probably going to be optimized away by LLVM as unreachable since <code>triple_input</code> is <code>nounwind</code>.</p>



<a name="180733562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180733562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180733562">(Nov 14 2019 at 14:07)</a>:</h4>
<p>oh yeah, I need to supress that I guess</p>



<a name="180733583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180733583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180733583">(Nov 14 2019 at 14:07)</a>:</h4>
<p>I think that just having no <code>uwtable</code> is good enough in practice to abort. The shim should only be needed on targets that require <code>uwtable</code> to be present for other reasons</p>



<a name="180733685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180733685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180733685">(Nov 14 2019 at 14:08)</a>:</h4>
<p>Hmm, actually this only works for targets that use dwarf unwinding. SjLj unwinding doesn't use unwinding tables and always works. And I have no idea wtf SEH will do here.</p>



<a name="180733874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180733874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180733874">(Nov 14 2019 at 14:10)</a>:</h4>
<p>The good news is, the overhead for abort on extern "C" unwinding is going to be 0 in most cases since it already aborts :)</p>



<a name="180734038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180734038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180734038">(Nov 14 2019 at 14:13)</a>:</h4>
<blockquote>
<p>looking at the c++ referenece manual, it suggested that if there is no catch block then C++ will terminate (which fits what I'm seeing)</p>
</blockquote>
<p>This makes sense. When unwinding hits a thread boundary, C++ calls <code>std::terminate</code>.</p>



<a name="180734064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180734064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180734064">(Nov 14 2019 at 14:13)</a>:</h4>
<blockquote>
<p>Hmm, actually this only works for targets that use dwarf unwinding. SjLj unwinding doesn't use unwinding tables and always works. And I have no idea wtf SEH will do here.</p>
</blockquote>
<p>yeah I  have been meaning to try this on windows -- I'm actually running windows, so that <em>should</em> be easy enough, except I've never tried to build Rust outside of WSL <span aria-label="laughter tears" class="emoji emoji-1f602" role="img" title="laughter tears">:laughter_tears:</span></p>



<a name="180734138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180734138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180734138">(Nov 14 2019 at 14:14)</a>:</h4>
<blockquote>
<p>I think that just having no <code>uwtable</code> is good enough in practice to abort. The shim should only be needed on targets that require <code>uwtable</code> to be present for other reasons</p>
</blockquote>
<p>I don't quite follow-- I think you're saying the current branch status itself is fine, since either (a) the c++ code needs uwtable and it aborts when it doesn't find it (as today) or (b) some other environments may not need uwtable, in which case they will get trapped by the unwinding?</p>



<a name="180734181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180734181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180734181">(Nov 14 2019 at 14:15)</a>:</h4>
<p>anyway i'd like to see the tra in action so I'll try to add the various attributes (and remove "nounwind") later on</p>



<a name="180734395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/180734395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#180734395">(Nov 14 2019 at 14:18)</a>:</h4>
<p>Windows and Android have the <code>requires_uwtable</code> target attribute set, which means that unwinding tables are always generated even with <code>panic=abort</code>. For those platforms we will need to perform extra work to abort on unwind.</p>



<a name="183316305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183316305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183316305">(Dec 13 2019 at 00:10)</a>:</h4>
<p>Hey <span class="user-mention" data-user-id="143274">@Amanieu</span> I made some more changes here, but i'm still not able to get a C++ exception to actually propagate through Rust code.  <a href="https://gist.github.com/nikomatsakis/904278ba6cd3922a1685ace9b979225a" target="_blank" title="https://gist.github.com/nikomatsakis/904278ba6cd3922a1685ace9b979225a">Here is the LLVM IR.</a> I still can't get a <code>throw 22</code> to propagate to Rust, I just see:</p>
<div class="codehilite"><pre><span></span>terminate called after throwing an instance of &#39;int&#39;
</pre></div>


<p>Any idea what's going wrong? </p>
<p>In any case, I'm not 100% sure what we <em>should</em> be doing here. For example, generating uwtable attributes just so that we can abort later seems a bit silly, but I figured I'd like to see it die in a controlled fashion first.</p>



<a name="183316470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183316470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183316470">(Dec 13 2019 at 00:13)</a>:</h4>
<p>I think what's happening here is due to 2 phase unwinding</p>



<a name="183316503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183316503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183316503">(Dec 13 2019 at 00:13)</a>:</h4>
<p>The 1st phases searches for a suitable catch, while the second phase unwinds until that catch and calls cleanups.</p>



<a name="183316555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183316555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183316555">(Dec 13 2019 at 00:14)</a>:</h4>
<p>However if there is no catch anywhere on the call chain then phase 1 fails and terminates.</p>



<a name="183316561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183316561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183316561">(Dec 13 2019 at 00:14)</a>:</h4>
<p>Your landingpad is defined as a cleanup, which means that it is only executed in phase 2.</p>



<a name="183316605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183316605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183316605">(Dec 13 2019 at 00:15)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> Could you point me to the Rust code for that again?</p>



<a name="183316612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183316612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183316612">(Dec 13 2019 at 00:15)</a>:</h4>
<p>Ah nevermind, found it.</p>



<a name="183316708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183316708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183316708">(Dec 13 2019 at 00:17)</a>:</h4>
<p>Yea, try defining the landingpad as a catch instead of a cleanup and see if that helps.</p>



<a name="183322216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183322216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183322216">(Dec 13 2019 at 02:02)</a>:</h4>
<p>Actually I've just thought of another potential issue: even with panic=abort, we need to make sure longjmp works correctly on Windows. This means that we must allow foreign exceptions to unwind through Rust code even with panic=abort.</p>



<a name="183322309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183322309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183322309">(Dec 13 2019 at 02:04)</a>:</h4>
<p>Re: that last, <span class="user-mention" data-user-id="116015">@Alex Crichton</span> says that already works; I can point you to the PR that fixed it</p>



<a name="183322406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183322406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183322406">(Dec 13 2019 at 02:06)</a>:</h4>
<p>Here: <a href="https://github.com/rust-lang/rust/pull/48572" target="_blank" title="https://github.com/rust-lang/rust/pull/48572">https://github.com/rust-lang/rust/pull/48572</a></p>



<a name="183322424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183322424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183322424">(Dec 13 2019 at 02:07)</a>:</h4>
<p><span class="user-mention" data-user-id="120076">@Kyle Strand</span> scroll up to the top of this thread for the context.</p>



<a name="183322472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183322472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183322472">(Dec 13 2019 at 02:08)</a>:</h4>
<blockquote>
<p>So I was thinking about how to measure the impact of a proposal where the C ABI permits unwinding but -- if we are <code>-Cpanic=abort</code> -- we abort if unwinding actually occurs (versus UB).</p>
</blockquote>



<a name="183322586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183322586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183322586">(Dec 13 2019 at 02:11)</a>:</h4>
<p><span class="user-mention" data-user-id="120076">@Kyle Strand</span> That PR on aborts if a Rust panic tries to unwind past <code>#[unwind(aborts)]</code>, but it lets foreign exceptions pass through. However if a foreign exception does unwind into code compiled with panic=aborts then we've still got UB.</p>



<a name="183322663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183322663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183322663">(Dec 13 2019 at 02:13)</a>:</h4>
<p>Are you saying that the landing pad generated by <code>unwind(aborts)</code> is different from the one generated by <code>-Cpanic=abort</code>?</p>



<a name="183322716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183322716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183322716">(Dec 13 2019 at 02:14)</a>:</h4>
<p>Or, oh, there's no landing pads. My bad.</p>



<a name="183322728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183322728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183322728">(Dec 13 2019 at 02:14)</a>:</h4>
<p>So we'd need to generate them but only if the function directly calls an extern function</p>



<a name="183322923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183322923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183322923">(Dec 13 2019 at 02:19)</a>:</h4>
<p>Except that we want to allow longjmp over Rust code when there are no destructors on the stack, since the current consensus is that is not UB.</p>



<a name="183322971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183322971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183322971">(Dec 13 2019 at 02:20)</a>:</h4>
<p>That should be allowed even with panic=abort</p>



<a name="183324834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183324834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183324834">(Dec 13 2019 at 03:05)</a>:</h4>
<p>Right; why is that UB?</p>



<a name="183324836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183324836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183324836">(Dec 13 2019 at 03:05)</a>:</h4>
<p>(currently)</p>



<a name="183325104"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183325104" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183325104">(Dec 13 2019 at 03:12)</a>:</h4>
<p>What effect does LLVM <code>nounwind</code> have in MSVC, anyway?</p>



<a name="183340945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183340945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183340945">(Dec 13 2019 at 09:21)</a>:</h4>
<p><code>nounwind</code> does not mean "does not unwind", but rather "does not unwind in certain ways"</p>



<a name="183340964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183340964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183340964">(Dec 13 2019 at 09:21)</a>:</h4>
<p><code>nounwind</code> functions can unwind with asynchronous exceptions on windows just fine (see the LLVM LangRef)</p>



<a name="183341022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183341022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183341022">(Dec 13 2019 at 09:22)</a>:</h4>
<p>on Linux, <code>nounwind</code> functions can unwind with forced unwinds just fine as well</p>



<a name="183341039"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183341039" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183341039">(Dec 13 2019 at 09:22)</a>:</h4>
<p>(e.g. like the ones used by <code>longjmp</code>, or <code>pthread_cancel</code>)</p>



<a name="183341151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183341151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183341151">(Dec 13 2019 at 09:24)</a>:</h4>
<blockquote>
<p>Right; why is that UB?</p>
</blockquote>
<p>Because there is no RFC guaranteeing that it isn't. I wrote one with Kyren for the UCGs to review.</p>



<a name="183357777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183357777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183357777">(Dec 13 2019 at 13:17)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> ok, well, I didn't try to make it a "catch" -- in part because in the C++ code I already <em>have</em> a catch in scope, so I'm surprised it's not being found. i.e., my C++ code is</p>
<div class="codehilite"><pre><span></span><span class="k">extern</span> <span class="s">&quot;C&quot;</span>
<span class="kt">int</span> <span class="n">triple_input</span><span class="p">(</span><span class="kt">int</span> <span class="n">input</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">throw</span> <span class="mi">22</span><span class="p">;</span>
<span class="p">}</span>

<span class="kt">int</span> <span class="n">main</span><span class="p">()</span> <span class="p">{</span>
    <span class="k">try</span> <span class="p">{</span>
        <span class="kt">int</span> <span class="n">input</span> <span class="o">=</span> <span class="mi">10</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">output</span> <span class="o">=</span> <span class="n">double_input</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
        <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="n">input</span><span class="o">&lt;&lt;</span><span class="s">&quot; * 2 = &quot;</span><span class="o">&lt;&lt;</span><span class="n">output</span><span class="o">&lt;&lt;</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">;</span>
    <span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;caught &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">i</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">;</span>
    <span class="p">}</span>
  <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>


<p>where <code>double_input</code> is defined in Rust and invokes <code>triple_input</code>.</p>



<a name="183357785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183357785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183357785">(Dec 13 2019 at 13:17)</a>:</h4>
<p>I'm also not sure how to do that :P and it sounds like more work</p>



<a name="183357870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183357870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183357870">(Dec 13 2019 at 13:18)</a>:</h4>
<p>as far as Windows and longjmp, I agree, we'd have to figure out this interaction, I'm mostly just trying to get some kind of rough-n-dirty upper bound on the overall size impact of pursuing a plan where "C" unwinds by default, but -Cpanic=abort doesn't just create UB if you happen to have unwinding occur (but rather aborts in a structured way)</p>



<a name="183357884"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183357884" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183357884">(Dec 13 2019 at 13:18)</a>:</h4>
<p>presumably it is possible to distinguish a longjmp unwind from other unwinds</p>



<a name="183357975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183357975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183357975">(Dec 13 2019 at 13:20)</a>:</h4>
<p>anyway I don't quite get why it's not working, there must be <em>some</em> other flag somewhere  that I'm overlooking I guess</p>



<a name="183358014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183358014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183358014">(Dec 13 2019 at 13:20)</a>:</h4>
<p>triple_input is <code>nounwind</code>, maybe that's the issue?</p>



<a name="183358046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183358046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183358046">(Dec 13 2019 at 13:21)</a>:</h4>
<p>ah, maybe it's the nounwind attributes</p>



<a name="183358205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183358205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183358205">(Dec 13 2019 at 13:23)</a>:</h4>
<p>er, I see we reached similar conclusion together :) yes, I'll disable those</p>



<a name="183358256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183358256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183358256">(Dec 13 2019 at 13:24)</a>:</h4>
<p>(for some weird reason your msg didn't show up until I refreshed...)</p>



<a name="183359654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183359654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183359654">(Dec 13 2019 at 13:43)</a>:</h4>
<p>Hmm, that doesn't seem to have made any difference, but I'm also wondering if I was wrong about that being the LLVM-IR. When I run <code>cargo rustc -- --emit llvm-ir</code> I actually get an error because the <code>rustc</code> command itself includes <code>--emit</code> flags.</p>



<a name="183359798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183359798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183359798">(Dec 13 2019 at 13:45)</a>:</h4>
<p>well, pretty sure that <a href="https://gist.github.com/0fde1684114f5b86847b4d4fb211c24f" target="_blank" title="https://gist.github.com/0fde1684114f5b86847b4d4fb211c24f">this is the LLVM IR</a>, but I don't see much</p>



<a name="183359810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183359810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183359810">(Dec 13 2019 at 13:45)</a>:</h4>
<p>/me shrugs</p>



<a name="183359960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183359960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183359960">(Dec 13 2019 at 13:47)</a>:</h4>
<p>OK, I'm about ready to give up :)</p>



<a name="183360135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183360135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183360135">(Dec 13 2019 at 13:49)</a>:</h4>
<p>I'd say <span class="user-mention" data-user-id="120076">@Kyle Strand</span> that we ought to try to write-up a summary and maybe ask for help from somebody who understands this stuff better to suggest (a) how to measure the impact and (b) what the right setup would even <em>look like</em> to enable us to abort when unwinding occurs</p>



<a name="183360439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183360439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183360439">(Dec 13 2019 at 13:53)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> how is <code>double_input</code> defined ? it just calls <code>triple_input</code> ?</p>



<a name="183360526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183360526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183360526">(Dec 13 2019 at 13:54)</a>:</h4>
<p>there is a lot of debug info and formatting going on in that LLVM-IR (using <code>-C debuginfo=0</code> should remove some of it)</p>



<a name="183360596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183360596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183360596">(Dec 13 2019 at 13:55)</a>:</h4>
<p>I suppose <code>double_input</code> prints something to the screen, and then calls <code>triple_input</code> ?</p>



<a name="183360687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183360687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183360687">(Dec 13 2019 at 13:56)</a>:</h4>
<p>the llvm-ir for that part looks ok to me, since <code>triple_input</code> can throw, it is called with <code>invoke</code>, and if that unwinds it goes to <code>cleanup</code>, which does some stuff i don't understand but then goes to <code>bb5</code> which traps</p>



<a name="183360721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183360721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183360721">(Dec 13 2019 at 13:57)</a>:</h4>
<p>ah, I see the problem, that shouldn't trap but continue unwinding</p>



<a name="183360752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183360752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183360752">(Dec 13 2019 at 13:57)</a>:</h4>
<p>or should it? are you compiling the Rust with <code>-C panic=abort</code> ? if so, that would be what you want</p>



<a name="183360763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183360763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183360763">(Dec 13 2019 at 13:57)</a>:</h4>
<p>(to let <code>triple_input</code> unwind without UB, and then abort)</p>



<a name="183554540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183554540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183554540">(Dec 16 2019 at 14:42)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> exactly, the intention was to see what it would take to make <code>-Cpanic=abort</code> <em>abort</em> if unwinding occurred, rather than creating UB. So far, I've been able to get it to abort, but not via the mechanism I expected =) i.e., it aborts because it can't find any in-scope <code>catch</code> handler, versus unwinding and then aborting when it passes into Rust code.</p>



<a name="183554559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183554559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183554559">(Dec 16 2019 at 14:42)</a>:</h4>
<p>I don't know exactly how C++ specific that is</p>



<a name="183554597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183554597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183554597">(Dec 16 2019 at 14:43)</a>:</h4>
<p>(e.g., maybe there are libunwind methods I could trigger that would just unwind more indiscriminantely?)</p>



<a name="183554621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183554621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183554621">(Dec 16 2019 at 14:43)</a>:</h4>
<p>I'm not sure I understand</p>



<a name="183554631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183554631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183554631">(Dec 16 2019 at 14:43)</a>:</h4>
<p>but I also don't know why it can't find the catch block in scope, since afaik we've setup the function's metadata correctly</p>



<a name="183554649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183554649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183554649">(Dec 16 2019 at 14:43)</a>:</h4>
<p>what don't you understand?</p>



<a name="183554657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183554657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183554657">(Dec 16 2019 at 14:43)</a>:</h4>
<p>From looking at the LLVM IR, it appears that if it unwinds, it would run the cleanup, and the cleanup aborts</p>



<a name="183554675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183554675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183554675">(Dec 16 2019 at 14:43)</a>:</h4>
<p>that is the goal, yes</p>



<a name="183554689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183554689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183554689">(Dec 16 2019 at 14:44)</a>:</h4>
<p>except that it's not what happens</p>



<a name="183554753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183554753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183554753">(Dec 16 2019 at 14:44)</a>:</h4>
<p>ah ok  :D, no idea why :/ from looking at the IR, it should work</p>



<a name="183554777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183554777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183554777">(Dec 16 2019 at 14:44)</a>:</h4>
<p>maybe the IR is missing something :/</p>



<a name="183555001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183555001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183555001">(Dec 16 2019 at 14:47)</a>:</h4>
<p>you might want to ask for help in the wg-llvm, somebody there might "just see" what's missing</p>



<a name="183555092"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183555092" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183555092">(Dec 16 2019 at 14:48)</a>:</h4>
<p>Yeah, maybe. The specific problem is that C++ terminates because it can't find any catch block for int</p>



<a name="183555260"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183555260" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183555260">(Dec 16 2019 at 14:50)</a>:</h4>
<p>Do you have the LLVM-IR produced by C++ ?</p>



<a name="183555287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183555287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183555287">(Dec 16 2019 at 14:50)</a>:</h4>
<p>or is there a way to combine them into a single .ll file that reproduces the problem? That would help</p>



<a name="183555314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183555314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183555314">(Dec 16 2019 at 14:50)</a>:</h4>
<p>I don't, but as we were typing I was thinking maybe I should look at that</p>



<a name="183555403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/implementing%20%22abort%20on%20FFI%20call%22/near/183555403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/implementing.20.22abort.20on.20FFI.20call.22.html#183555403">(Dec 16 2019 at 14:51)</a>:</h4>
<p>that might help, I recommend avoiding "print" functionality, and setting debug-info to "off" to get the simplest IR possible</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>